﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using CRM.Entity;
using CRM.BLL;
using DP.Web.UI;
using DP.Common;


namespace CRM.Web.MessagingManage
{
    public partial class SMSSend : Common.PageBase
    {
        private T_SMS_SEND_BLL bll = new T_SMS_SEND_BLL();

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            PageHelper.SetPrePageUrl(this.Page);
            if (PageHelper.GetQueryString(this.Page, "OPENTYPE") == "NEWPAGE")
            {
                btnCancel.Value = "关闭";
                btnCancel.Attributes["onclick"] = "closeSelf();";
            }
            else
            {
                PageHelper.SetGoBackUrl(this.Page, btnCancel, StaticConstant.NotBackUrl);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {


                pageDataInit();
            }
        }

        #region 页面初始化数据绑定




        #endregion

        private void pageDataInit()
        {
            txtTEL_TO.Text = PageHelper.GetQueryString(this.Page, "PHONE");
            txtBODYS.Text = PageHelper.GetQueryString(this.Page, "BODYS");
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {

            int status = 0;
            string tel_to = this.txtTEL_TO.Text.Trim();
            if (tel_to.Contains(';'))
            {
                string[] tel_arg = tel_to.Split(';');

                for (int i = 0; i < tel_arg.Length; i++)
                {
                    if (tel_arg[i].ToString().Length != 11)
                    {
                        tel_arg[i].Remove(0);
                    }
                }

                if (tel_arg.Length >= 2)
                    status = 1;
            }

            T_SMS_SEND_Entity entity = new T_SMS_SEND_Entity();

            PageHelper.GetControlValue<T_SMS_SEND_Entity>(this.Page, ref entity);
            entity.BUSINESSDIVISIONCODE = _userLoginInfo.UserEntity.BUSINESSDIVISIONCODE;
            entity.BUSINESSDIVISIONID = _userLoginInfo.UserEntity.BUSINESSDIVISIONID;
            entity.BUSINESSDIVISIONNAME = _userLoginInfo.UserEntity.BUSINESSDIVISIONNAME;
            entity.CREATETIME = DateTime.Now;
            entity.SDATE = DateTime.Now.ToString("yyyyMMdd");
            entity.STIME = DateTime.Now.ToString("HHmmss");
            entity.GHID = _userLoginInfo.UserEntity.USERID.ToString();
            entity.UINFO = _userLoginInfo.UserEntity.USERNAME.ToString();
            entity.LEVELS = status;

            

            long rel = bll.Insert(entity);
            if (rel > 0)
            {
                if (PageHelper.GetQueryString(this.Page, "OPENTYPE") == "NEWPAGE")
                {
                    PageHelper.ExecuteJS("closeSelf();");
                }
                else
                {
                    PageHelper.ShowMessage(this.Page, "提交发送成功！", "SMSSendList.aspx");
                }
            }
            else
            {
                PageHelper.ShowMessage(this.Page, "提交发送失改！");
            }

        }
    }
}
